/**
 * @fileOverview 
 * Defines utility functions to be used in unittests.
 * @author Igor Kulkin <igor.kulkin@gmail.com>
 */

var EPSILON = 1e-7;


/**
 * Checks whether two given floating point numbers are equal with
 * EPSILON tolerance.
 * @param {String} [comment] Comment explaining the purpose of this assertion.
 * @param {Number} expectedValue Expected value.
 * @param {Number} actualValue Actual value.
 * @thros {JsUnitException} Throws exception if the assertion doesn't pass.
 */
function assertAlmostEquals() {
  var comment = null;
  var expectedValue = arguments[0];
  var actualValue = arguments[1];
  if (arguments.length == 3) {
    comment = arguments[0];
    expectedValue = arguments[1];
    actualValue = arguments[2];
  }
  if (Math.abs(expectedValue - actualValue) > EPSILON) {
    throw new JsUnitException(comment, 'Expected <' + expectedValue +
                              '> but was <' + actualValue + '>');
  }
}


/**
 * Checks whether a given Vector has expected coordinates.
 * @param {String} [comment] Comment explaining the purpose of this assertion.
 * @param {Number} expectedX Expected x-coordinate value.
 * @param {Number} expectedY Expected y-coordinate value.
 * @param {Vector} vector Actual vector object.
 * @thros {JsUnitException} Throws exception if the assertion doesn't pass.
 */
function assertVectorCoords() {
  var comment = null;
  var expectedX = arguments[0];
  var expectedY = arguments[1];
  var vector = arguments[2];
  if (arguments.length == 4) {
    comment = arguments[0];
    expectedX = arguments[1];
    expectedY = arguments[2];
    vector = arguments[3];
  }
  if (Math.abs(expectedX - vector.x) > EPSILON ||
      Math.abs(expectedY - vector.y) > EPSILON) {
    throw new JsUnitException(comment, 'Expected vector <' + expectedX + ',' +
                              expectedY + '> but was <' + vector.x + ',' +
                              vector.y + '>');
  }
}
